home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / sgwnd10 / connect.cls < prev    next >
Encoding:
Visual Basic class definition  |  1998-07-15  |  4.2 KB  |  155 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "Connect"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = True
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = True
  10. Attribute VB_Description = "Stinga sgWindow Wizard"
  11. Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
  12. Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
  13. '--------------------------------------------------------------------------
  14. ' File: CONNECT.CLS
  15. '
  16. ' This file is part of the 'Stinga sgWindow Wizard' project.
  17. ' Copyright (C) 1998 Stinga
  18. ' All rights reserved.
  19. '
  20. '--------------------------------------------------------------------------
  21.  
  22. Option Explicit
  23.  
  24. Implements IDTExtensibility
  25.  
  26. Public FormDisplayed          As Boolean
  27. Public VBInstance             As VBIDE.VBE
  28. Dim mcbMenuCommandBar         As Office.CommandBarControl
  29. Dim mfrmAddIn                 As New frmWizard
  30. Public WithEvents MenuHandler As CommandBarEvents          'command bar event handler
  31. Attribute MenuHandler.VB_VarHelpID = -1
  32.  
  33.  
  34. Sub Hide()
  35.     
  36.     On Error Resume Next
  37.     
  38.     FormDisplayed = False
  39.     mfrmAddIn.Hide
  40.    
  41. End Sub
  42.  
  43. Sub Show(nPage%)
  44.     On Error Resume Next
  45.     
  46.     If mfrmAddIn Is Nothing Then
  47.         Set mfrmAddIn = New frmWizard
  48.     End If
  49.     
  50.     Set mfrmAddIn.VBInstance = VBInstance
  51.     Set mfrmAddIn.Connect = Me
  52.     mfrmAddIn.SetStep 0, 0
  53.     FormDisplayed = True
  54.     mfrmAddIn.Clear
  55.     mfrmAddIn.Show
  56.    
  57. End Sub
  58.  
  59. '------------------------------------------------------
  60. 'this method adds the Add-In to VB
  61. '------------------------------------------------------
  62. Private Sub IDTExtensibility_OnConnection(ByVal VBInst As Object, ByVal ConnectMode As vbext_ConnectMode, ByVal AddInInst As VBIDE.AddIn, custom() As Variant)
  63.     
  64.     On Error GoTo error_handler
  65.     
  66.     'save the vb instance
  67.     Set VBInstance = VBInst
  68.     
  69.     'this is a good place to set a breakpoint and
  70.     'test various addin objects, properties and methods
  71.     Debug.Print VBInst.FullName
  72.  
  73.     If ConnectMode = vbext_cm_External Then
  74.         'Used by the wizard toolbar to start this wizard
  75.         'Me.Show 0
  76.     Else
  77.         Set mcbMenuCommandBar = AddToAddInCommandBar("Stinga sgWindow Wizard...")
  78.         'sink the event
  79.         Set Me.MenuHandler = VBInst.Events.CommandBarEvents(mcbMenuCommandBar)
  80.     End If
  81.   
  82.     If ConnectMode = vbext_cm_AfterStartup Then
  83.     End If
  84.   
  85.     Exit Sub
  86.     
  87. error_handler:
  88.     
  89.     MsgBox Err.Description
  90.     
  91. End Sub
  92.  
  93. '------------------------------------------------------
  94. 'this method removes the Add-In from VB
  95. '------------------------------------------------------
  96. Private Sub IDTExtensibility_OnDisconnection(ByVal RemoveMode As vbext_DisconnectMode, custom() As Variant)
  97.     
  98.     On Error Resume Next
  99.     
  100.     'delete the command bar entry
  101.     mcbMenuCommandBar.Delete
  102.     
  103.     'shut down the Add-In
  104.     If FormDisplayed Then
  105.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "1"
  106.         FormDisplayed = False
  107.     Else
  108.         SaveSetting App.Title, "Settings", "DisplayOnConnect", "0"
  109.     End If
  110.     
  111.     Unload mfrmAddIn
  112.     Set mfrmAddIn = Nothing
  113.  
  114. End Sub
  115.  
  116. Private Sub IDTExtensibility_OnStartupComplete(custom() As Variant)
  117. End Sub
  118.  
  119. Private Sub IDTExtensibility_OnAddInsUpdate(custom() As Variant)
  120. '
  121. End Sub
  122.  
  123. 'this event fires when the menu is clicked in the IDE
  124. Private Sub MenuHandler_Click(ByVal CommandBarControl As Object, handled As Boolean, CancelDefault As Boolean)
  125.     Me.Show 0
  126. End Sub
  127.  
  128. Function AddToAddInCommandBar(sCaption As String) As Office.CommandBarControl
  129.     Dim cbMenuCommandBar As Office.CommandBarControl  'command bar object
  130.     Dim cbMenu As Object
  131.   
  132.     On Error GoTo AddToAddInCommandBarErr
  133.     
  134.     'see if we can find the Add-Ins menu
  135.     Set cbMenu = VBInstance.CommandBars("Add-Ins")
  136.     If cbMenu Is Nothing Then
  137.         'not available so we fail
  138.         Exit Function
  139.     End If
  140.     
  141.     'add it to the command bar
  142.     Set cbMenuCommandBar = cbMenu.Controls.Add(1)
  143.     'set the caption
  144.     cbMenuCommandBar.Caption = sCaption
  145.     
  146.     Set AddToAddInCommandBar = cbMenuCommandBar
  147.     
  148.     Exit Function
  149.     
  150. AddToAddInCommandBarErr:
  151.  
  152. End Function
  153.  
  154.  
  155.